package com.cgydu.controller;

import com.cgydu.entity.PageBean;
import com.cgydu.entity.Product;
import com.cgydu.service.ProductService;
import com.cgydu.service.impl.ProductServiceImpl;
import com.cgydu.utils.Constants;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;

/**
 * projectName: day25_store
 * author: CGY
 * time: 2020/8/29 10:32
 * description:
 */
@WebServlet("/product")
public class ProductController extends BaseController{

    public String getProducts(HttpServletRequest request, HttpServletResponse response) throws SQLException {

        //1.获取请求参数
        String tid = request.getParameter("tid");
        String currentPage = request.getParameter("currentPage");
        String pageSize = request.getParameter("pageSize");

        //2.调用业务逻辑
        ProductService productService = new ProductServiceImpl();
        PageBean<Product> pageBean = productService.findAll(tid, currentPage, pageSize);

        //3.响应
        request.setAttribute("pageBean",pageBean);
        return Constants.FORWARD_ACTION + "/goodsList.jsp";

    }
    public String detail(HttpServletRequest request, HttpServletResponse response) throws SQLException {

        //1.获取请求参数
        String pid = request.getParameter("pid");
        System.out.println("pid = " + pid);

        //2.调用业务逻辑
        ProductService productService = new ProductServiceImpl();
        Product product = productService.findProductByPid(pid);
        //3.响应
        request.setAttribute("product", product);
        return Constants.FORWARD_ACTION + "/goodsDetail.jsp";
    }
}